package com.qf.controller;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Springmvc接收前台请求参数的方式
 *
 */
@Controller
@RequestMapping("/requestData")
public class ReceiveRequestParameController {
    /**
     * 路径携带参数
     * url?参数名称1=参数值1&参数名称2=值2
     * 注意事项: 当前方法形式参数名称必须和路径上的参数名称一致!,否则获取不到!
     */
    @RequestMapping("/firstReq")
    public String getRequestFirst(
            Integer id,
             String username,
            String address,
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date time){

        System.out.println("编号是:"+id);
        System.out.println("姓名是:"+username);
        System.out.println("地址是:"+address);
        System.out.println("出生日期是:"+time);
        return "ok";
    }
    @RequestMapping("/secondReq")
    public String secondRequest(HttpServletRequest request){
        //获取参数数据
        String id = request.getParameter("id");
        String username = request.getParameter("username");
        String address = request.getParameter("address");
        String time = request.getParameter("time");
        System.out.println("id:"+id);
        System.out.println("username:"+username);
        System.out.println("address:"+address);
        System.out.println("time:"+time);
        return "ok";

    }
}
